package com.yuantu.judiciary.controller;

import com.yuantu.judiciary.annotation.Log;
import com.yuantu.judiciary.common.Response;
import com.yuantu.judiciary.common.ResponseFactory;
import com.yuantu.judiciary.model.form.DiscountCodeForm;
import com.yuantu.judiciary.model.form.DiscountCodeStatusForm;
import com.yuantu.judiciary.model.vo.*;
import com.yuantu.judiciary.service.IDiscountCodeService;
import com.yuantu.judiciary.service.IMembershipRankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 邀请码模块
 *
 * @author syw
 * @since 2023-08-17
 **/
@RestController
@RequestMapping("/membership")
@Api(tags = "会员管理模块")
@RequiredArgsConstructor
public class MembershipRankController extends BaseController {


    private final IMembershipRankService membershipRankService;


    @ApiOperation(value = "会员配置查询列表")
    @PostMapping("/list")
    public Response<List<MembershipRankVO>> membershipRankList() {

        return ResponseFactory.okResponse(membershipRankService.membershipRankList());
    }


    @Log(title = "新增/修改会员配置")
    @ApiOperation(value = "新增/修改会员配置")
    @PostMapping("/update")
    public Response<Long> updateMembershipRank(@RequestBody @Validated MembershipRankVO membershipRank) {

        return ResponseFactory.okResponse(membershipRankService.updateMembershipRank(membershipRank));
    }


    @Log(title = "删除会员配置")
    @ApiOperation(value = "删除会员配置")
    @GetMapping("/remove")
    public Response<Boolean> removeMembershipRank(@RequestParam Long membershipRankId) {

        return ResponseFactory.okResponse(membershipRankService.removeMembershipRank(membershipRankId));
    }


    @ApiOperation(value = "会员等级人数")
    @PostMapping("/num")
    public Response<List<MembershipNumVO>> getMembershipNum() {

        return ResponseFactory.okResponse(membershipRankService.getMembershipNum());
    }

    @ApiOperation(value = "会员管理列表")
    @PostMapping("/manage")
    public Response<PageVO<MembershipInfoVO>> membershipManageList(@RequestParam(required = false) String accountInfo,
                                                                   @PageableDefault(sort = "createTime", direction = Sort.Direction.DESC) Pageable pageable) {

        return ResponseFactory.okResponse(membershipRankService.membershipManageList(accountInfo, pageable));
    }


    @Log(title = "修改会员有关信息")
    @ApiOperation(value = "修改会员有关信息")
    @PostMapping("/update/info")
    public Response<Boolean> updateMembershipInfo(@RequestBody @Validated MembershipSimpleInfoVO membershipSimple) {

        return ResponseFactory.okResponse(membershipRankService.updateMembershipInfo(membershipSimple));
    }


}
